package com.heba.decoration;

import android.graphics.Rect;

import androidx.annotation.NonNull;;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

/**
 * Created by jason on 2019/7/1.
 */
public class GridVerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {

    private int space;
    private int spanCount;

    public GridVerticalSpaceItemDecoration(int space, int spanCount) {
        this.space = space;
        this.spanCount = spanCount;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
//        outRect.bottom = space;
//        outRect.left = space;
//        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
//        if (parent.getChildLayoutPosition(view) % spanCount == 0) {
//            outRect.left = 0;
//        }

        //如果是左边第一个item的话，不添加左边间距
//        if (parent.getChildAdapterPosition(view) % spanCount == 0) {
//            outRect.set(0, 0, 0, space);
//        } else {
//            outRect.set(space, 0, 0, space);
//        }

        outRect.set(0, 0, space, space);
    }
}
